﻿using Projet_IMA.Light;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Projet_IMA.Base;

namespace Projet_IMA.Habillage.Material
{
    public class MaterialTexture : MaterialBase
    {
        private TextureImage texture;

        public MaterialTexture(TextureImage texture)
        {
            this.texture = texture;
        }

        public override System.Drawing.Color GetColor(float u, float v, Base.V3 normal, V3 du, V3 dv)
        {
            Couleur newCouleur = new Couleur();
            Couleur couleur = texture.GetColor(u, v);

            if (Bump != null)
                MakeBump(u, v, normal, du, dv);

            foreach (LightBase light in this.scene.AllLights)
            {
                if (AsDiffus && AsSpecular)
                {
                    newCouleur += (DiffusIntensity * light.ComputeDiffusColor(normal, couleur)) + (SpecularIntensity * light.ComputeSpecularColor(normal, couleur, scene.CameraDirection, SpecularShininess));
                }
                else if (AsDiffus)
                {
                    newCouleur += light.ComputeDiffusColor(normal, couleur);
                }
                else if (AsSpecular)
                {
                    newCouleur += light.ComputeSpecularColor(normal, couleur, scene.CameraDirection, SpecularShininess);
                }
            }
            
            return Couleur.ToWindowsColor(newCouleur);
        }
    }
}
